package com.tzbank.back.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tzbank.back.dao.UserRoleMapper;
import com.tzbank.back.service.UserRoleService;
import com.tzbank.entity.backstage.UserRole;
import com.tzbank.utils.CodeUtil;
import com.tzbank.utils.ResultUtil;

@Service
public class UserRoleServiceImpl implements UserRoleService {

	@Autowired
	private UserRoleMapper userRoleMapper;

	@Transactional
	@Override
	public Map<String, Object> deleteUserRole(UserRole userRole) throws Exception{
		this.userRoleMapper.deleteUserRole(userRole);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Transactional
	@Override
	public Map<String, Object> insertUserRole(UserRole userRole) throws Exception{
		this.userRoleMapper.insertUserRole(userRole);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

	@Override
	public Map<String, Object> selectUserRoleByAutoId(int autoId) throws Exception{
		UserRole userRole = this.userRoleMapper.selectUserRoleByAutoId(autoId);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), userRole);
	}

	@Override
	public Map<String, Object> selectUserRoleList() throws Exception{
		List<UserRole> userRoles = this.userRoleMapper.selectUserRoleList();
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), userRoles);
	}

	@Transactional
	@Override
	public Map<String, Object> updateUserRole(UserRole userRole) throws Exception{
		this.userRoleMapper.updateUserRole(userRole);
		return ResultUtil.resultMap(CodeUtil.CODE_200.getName(), CodeUtil.CODE_200.getCode(), null);
	}

}
